package org.leumasjaffe.initiativeTracker.event;


import java.awt.event.ActionEvent;

import javax.swing.Action;

import org.leumasjaffe.initiativeTracker.Constants;
import org.leumasjaffe.initiativeTracker.view.InitiativeFrame;

@SuppressWarnings("serial")
public class ChangePageAction extends InitiativeTrackerAction implements Action {
	private final int increment;
	
	public ChangePageAction(String text, int increment) {
		super(text);
		this.increment = increment;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (inBounds()) {
			Constants.pageNum += this.increment;
			gui.repage();
		}
	}
	
	private boolean inBounds() {
		int newPos = (Constants.pageNum+this.increment)*InitiativeFrame.pageLength;
		return 0 <= newPos && newPos < list.size();
	}
	
}